#define _CRT_SECURE_NO_WARNINGS 1
#include"tree.h"
void init(t** p)
{
	assert(*p);
	(*p)->data = 10;
	(*p)->left = NULL;
	(*p)->right = NULL;
}

void push(t** p, int x)
{
	if ((*p)->left == NULL && (*p)->right == NULL)
	{
		t* new = (t*)malloc(sizeof(t));
		assert(new);
		new->data = x;
		new->left = NULL;
		new->right = NULL;
		if (x < (*p)->data)
		{
			(*p)->left = new;
		}
		else
		{
			(*p)->right = new;
		}
	}
	else
	{
		t* curleft = (*p);
		t* curright = (*p);
		if (x < (*p)->data)
		{
			while (curleft->left)
			{
				curleft = curleft->left;
			}
			t* new = (t*)malloc(sizeof(t));
			assert(new);
			new->data = x;
			new->left = NULL;
			new->right = NULL;
			if (x < curleft->data)
			{
				curleft->left = new;
			}
			else
			{
				curleft->right = new;
			}
		}
		else
		{
			while (curright->right)
			{
				curright = curright->right;
			}
			t* new = (t*)malloc(sizeof(t));
			assert(new);
			new->data = x;
			new->left = NULL;
			new->right = NULL;
			if (x < curright->data)
			{
				curright->left = new;
			}
			else
			{
				curright->right = new;
			}
		}
	}
}
void print(t* p)
{
	if (p == NULL)
		return NULL;
	printf("%d->", p->data);
	print(p->left);
	print(p->right);
}